package com.huahai.security.core.validate.code;

import com.huahai.security.core.properties.SecurityConstants;
import com.huahai.security.core.supports.ResultResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: Jun
 * @Date: 2020/7/17
 */
@RestController
public class ValidateCodeController {

    @Autowired
    private ValidateCodeProcessorHolder validateCodeProcessorHolder;

    /**
     * 创建验证码，根据验证码类型不同 ，调用不同的 {@link ValidateCodeProcessor} 接口实现
     *
     * @param request
     * @param response
     * @param type
     * @throws Exception
     */
    @GetMapping(SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{type}")
    public ResultResponse createCode(HttpServletRequest request, HttpServletResponse response, @PathVariable("type") String type) throws Exception {
        return validateCodeProcessorHolder.findValidateCodeProcessor(type).create(request, response);
    }
}
